function hfile = prt_ConvertToMS(hfile, tr)
% PRT::ConvertToMS  - convert a volume-based PRT to ms-based
%
% FORMAT:       [prt] = prt.ConvertToMS(tr)
%
% Input fields:
%
%       tr          TR
%
% Output fields:
%
%       prt         altered protocol

% Version:  v0.7b
% Build:    7090213
% Date:     Sep-02 2007, 1:27 PM CEST
% Author:   Jochen Weber, Brain Innovation, B.V., Maastricht, NL
% URL/Info: http://wiki.brainvoyager.com/BVQXtools

% argument check
if nargin < 2 || ...
    numel(hfile) ~= 1 || ...
   ~isBVQXfile(hfile, 'prt') || ...
   ~isa(tr, 'double') || ...
    numel(tr) ~= 1 || ...
    isinf(tr) || ...
    isnan(tr) || ...
    tr < 1 || ...
    tr ~= fix(tr)
    error( ...
        'BVQXfile:BadArgument', ...
        'Invalid call to %s.', ...
        mfilename ...
    );
end
bc = bvqxfile_getcont(hfile.L);

% return if not in volumes
if isempty(bc.ResolutionOfTime) || ...
    lower(bc.ResolutionOfTime(1)) ~= 'v'
    return;
end

% iterate over conditions
c = bc.Cond;
for cc = 1:numel(c)
    bc.Cond(cc).OnOffsets = ...
        [(c(cc).OnOffsets(:, 1) - 1) * tr, c(cc).OnOffsets(:, 2) * tr];
end

% set to MS
bc.ResolutionOfTime = 'msec';
bvqxfile_setcont(hfile.L, bc);
